<template>
    <div class="personal-center">
        <!-- 顶部信息区域 -->
        <div class="top-section">
            <div class="top-left">
                <p class="company">课程宝</p>
                <p class="name">{{userInfo.name}}</p>
                <p class="phone">手机号：{{userInfo.phone}}</p>
            </div>
            <div class="top-right">
                <p class="customer-service">客服电话：020-12331231</p>
                <div
                        class="verified-tag"
                        :class="userInfo.isKyc === 1 ? 'verified' : 'unverified'"
                >
                    {{ userInfo.isKyc === 1 ? '已认证' : '未认证' }}
                </div>
            </div>
        </div>

        <!-- 功能列表区域 -->
        <ul class="function-list">
            <li
                    @click="goView(item)"
                    class="function-item"
                    v-for="(item, index) in functionItems"
                    :key="index"
            >
                <div class="left-content">
                    <span class="icon" :class="item.icon"></span>
                    <span class="text">{{ item.text }}</span>
                </div>
                <span class="arrow">></span>
            </li>
        </ul>

        <!-- 底部导航区域 -->
        <div class="bottom-nav">
            <div
                    class="nav-item"
                    :class="{ active: currentTab === 'home' }"
                    @click="currentTab = 'home'"
            >
                <i class="icon-home"></i>
                <span>首页</span>
            </div>
            <div
                    class="nav-item"
                    :class="{ active: currentTab === 'course' }"
                    @click="currentTab = 'course'"
            >
                <i class="icon-course"></i>
                <span>课程管理</span>
            </div>
            <div
                    class="nav-item"
                    :class="{ active: currentTab === 'personal' }"
                    @click="currentTab = 'personal'"
            >
                <i class="icon-personal"></i>
                <span>个人中心</span>
            </div>
        </div>
    </div>
</template>

<script>
    import {saveUserInfo} from '@/utils/userStorage';
    import {getUserInfo} from '@/api/index.js'

    export default {
        name: "ProfilePage",
        data() {
            return {
                functionItems: [
                    /*{ icon: "icon-message", text: "我的消息" },*/
                    {icon: "icon-bankcard", text: "我的银行卡", path: "/profile/bankCard"},
                    /*{ icon: "icon-question", text: "常见问题" },*/
                    {icon: "icon-complain", text: "我要投诉", path: "/profile/complain"},
                ],
                currentTab: "personal",
                userInfo: {}
            };
        },
        methods: {
            goView(item) {
                if (item.path) {
                    this.$router.push(item.path);
                }
            },
            async getUserInfo() {
                const res = await getUserInfo();
                let userData = res.data;
                this.userInfo = userData;
                saveUserInfo(userData);
            }
        },
        mounted() {
            this.getUserInfo();
        }
    };
</script>

<style scoped>
    .personal-center {
        background-color: #f5f5f5;
        min-height: 100vh;
        padding-bottom: 60px;
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
        Arial, sans-serif;
    }

    /* 顶部信息 */
    .top-section {
        display: flex;
        justify-content: space-between;
        align-items: center;
        /*background: linear-gradient(135deg, #6cc1ff, #407fff);*/
        background: linear-gradient(135deg, #50aee5,#4a90e2);
        color: #fff;
        padding: 16px 12px;
        border-radius: 0 0 12px 12px;
        margin-bottom: 12px;
    }

    .top-left .company {
        font-size: 18px;
        font-weight: bold;
    }

    .top-left .name,
    .top-left .phone {
        font-size: 14px;
    }

    .top-right {
        text-align: right;
    }

    .customer-service {
        font-size: 14px;
    }

    .verified-tag {
        display: inline-block;
        background-color: #ffb800;
        padding: 4px 8px;
        border-radius: 12px;
        font-size: 12px;
    }

    .verified {
        background-color: #e6ffed;
        color: #1a7f37;
    }
    .unverified {
        background-color: #f5f5f5;
        color: #999;
    }

    /* 功能列表 */
    .function-list {
        list-style: none;
        margin: 0 12px;
        padding: 0;
        background: #fff;
        border-radius: 12px;
        overflow: hidden;
    }

    .function-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 18px 20px;
        border-bottom: 1px solid #f0f0f0;
    }

    .function-item:last-child {
        border-bottom: none;
    }

    .function-item:hover {
        background-color: #f9f9f9;
    }

    /* 左侧内容：图标 + 文本 */
    .left-content {
        display: flex;
        align-items: center;
    }

    .icon {
        width: 24px;
        height: 24px;
        margin-right: 12px;
        background-size: contain;
        background-repeat: no-repeat;
    }

    .text {
        font-size: 14px;
        color: #333;
    }

    /* 箭头 */
    .arrow {
        font-size: 16px;
        color: #ccc;
    }

    /* 示例图标 */
    .icon-message {
        background-image: url("@/assets/icons/message.png");
    }

    .icon-bankcard {
        background-image: url("@/assets/icons/money.png");
    }

    .icon-question {
        background-image: url("@/assets/icons/question.png");
    }

    .icon-complain {
        background-image: url("@/assets/icons/complaint.png");
    }

    /* 底部导航 */
    .bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
        background-color: #fff;
        border-top: 1px solid #e5e5e5;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 56px;
    }

    .nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        font-size: 12px;
        color: #666;
    }

    .nav-item.active {
        color: #407fff;
    }

    .nav-item i {
        width: 24px;
        height: 24px;
        background-size: contain;
    }
</style>
